#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: rename_history_clamp.py
# @time: 2021/4/9 16:45
# @desc:
from utils.mongo_tools import retrieve_all_mongo_values, update_mongo_value
from views.crud import send_to_message_queue
from views.configs import *

history_clamp = retrieve_all_mongo_values(
    {},
    database_name=MONGO_DATABASE_NAME,
    collection_name=HISTORY_CLAMP_COLLECTION,
)

count = 0
for i in history_clamp:
    path_list = i["file"][CATPART_OSS_ADDRESS].split("/")
    if len(path_list[-2]) > 2:
        i["name"] = path_list[-2] + "_" + path_list[-1]
        count += 1

        updateInfo = {"$set": {"name": i["name"]}}
        update_mongo_value(
            {"number": i["number"]},
            updateInfo,
            database_name=MONGO_DATABASE_NAME,
            collection_name=HISTORY_CLAMP_COLLECTION,
        )

for i in history_clamp:
    i["file"][STP_OSS_ADDRESS] = i["file"][CATPART_OSS_ADDRESS].replace("CATPart", "stp")
    i["file"][STL_OSS_ADDRESS] = i["file"][CATPART_OSS_ADDRESS].replace("CATPart", "stl")
    i["file"][GLTF_OSS_ADDRESS] = i["file"][CATPART_OSS_ADDRESS].replace("CATPart", "glb")
    updateInfo = {"$set": i}
    update_mongo_value(
        {"number": i["number"]},
        updateInfo,
        database_name=MONGO_DATABASE_NAME,
        collection_name="history_clamp",
    )


